package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxReceiveAddress;
import com.ruoyi.system.service.fx.IFxReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收货地址维护Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/fx/address")
public class FxReceiveAddressController extends BaseController {
    @Autowired
    private IFxReceiveAddressService fxReceiveAddressService;

    /**
     * 查询收货地址维护列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxReceiveAddress fxReceiveAddress) {
        fxReceiveAddress.setUserId(getUserId());
        startPage();
        List<FxReceiveAddress> list = fxReceiveAddressService.selectFxReceiveAddressList(fxReceiveAddress);
        return getDataTable(list);
    }

    /**
     * 导出收货地址维护列表
     */
    @Log(title = "收货地址维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxReceiveAddress fxReceiveAddress) {
        List<FxReceiveAddress> list = fxReceiveAddressService.selectFxReceiveAddressList(fxReceiveAddress);
        ExcelUtil<FxReceiveAddress> util = new ExcelUtil<FxReceiveAddress>(FxReceiveAddress.class);
        util.exportExcel(response, list, "收货地址维护数据");
    }

    /**
     * 获取收货地址维护详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxReceiveAddressService.selectFxReceiveAddressById(id));
    }

    /**
     * 收货地址列表
     *
     * @param fxReceiveAddress
     * @return
     */
    @GetMapping("/getDefault")
    public AjaxResult getDefault(FxReceiveAddress fxReceiveAddress) {
        return success(fxReceiveAddressService.selectRecentlyOrDefault(fxReceiveAddress));
    }

    /**
     * 获取收货地址列表
     *
     * @param fxReceiveAddress
     * @return
     */
    @GetMapping("/getDefaultList")
    public AjaxResult getDefaultList(FxReceiveAddress fxReceiveAddress) {
        return success(fxReceiveAddressService.selectAddressList(fxReceiveAddress));
    }

    /**
     * 新增收货地址维护
     */
    @Log(title = "收货地址维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxReceiveAddress fxReceiveAddress) {
        fxReceiveAddress.setUserId(getUserId());
        return toAjax(fxReceiveAddressService.save(fxReceiveAddress));
    }

    /**
     * 修改收货地址维护
     */
    @Log(title = "收货地址维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxReceiveAddress fxReceiveAddress) {
        return toAjax(fxReceiveAddressService.save(fxReceiveAddress));
    }

    /**
     * 删除收货地址维护
     */
    @Log(title = "收货地址维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxReceiveAddressService.deleteFxReceiveAddressByIds(ids));
    }
}
